JsonSerializer

Ecng.Serialization

Provides JSON serialization and deserialization for a given type.

Herda de: Serializer<T>

Implementa: IJsonSerializer

Propriedades

BufferSize
public int BufferSize { get; set; }
value = jsonSerializer.BufferSize
jsonSerializer.BufferSize = value

Gets or sets the buffer size used during serialization and deserialization.

Encoding
public Encoding Encoding { get; set; }
value = jsonSerializer.Encoding
jsonSerializer.Encoding = value

Gets or sets the text encoding used for serialization. Defaults to UTF8.

EncryptedAsByteArray
public bool EncryptedAsByteArray { get; set; }
value = jsonSerializer.EncryptedAsByteArray
jsonSerializer.EncryptedAsByteArray = value

Gets or sets a value indicating whether encrypted values are handled as byte arrays.

EnumAsString
public bool EnumAsString { get; set; }
value = jsonSerializer.EnumAsString
jsonSerializer.EnumAsString = value

Gets or sets a value indicating whether enums should be serialized as strings.

FileExtension
public override string FileExtension { get; }
value = jsonSerializer.FileExtension

Gets the file extension associated with the JSON serializer.

FillMode
public bool FillMode { get; set; }
value = jsonSerializer.FillMode
jsonSerializer.FillMode = value

Gets or sets a value indicating whether the fill mode is enabled.

Indent
public bool Indent { get; set; }
value = jsonSerializer.Indent
jsonSerializer.Indent = value

Gets or sets a value indicating whether the JSON output should be indented.

NullValueHandling
public NullValueHandling NullValueHandling { get; set; }
value = jsonSerializer.NullValueHandling
jsonSerializer.NullValueHandling = value

Gets or sets the null value handling option for JSON serialization.

SecureStringEncryptor
public ISecureStringEncryptor SecureStringEncryptor { get; set; }
value = jsonSerializer.SecureStringEncryptor
jsonSerializer.SecureStringEncryptor = value

Gets or sets the local SecureString encryptor used by this serializer. When set, it overrides Encryptor only while this serializer is serializing or deserializing.

Métodos

CreateDefault
public static JsonSerializer<T> CreateDefault()
result = JsonSerializer.CreateDefault()

Creates a default instance of the JSON serializer with preconfigured settings.

Retorna: A default JsonSerializer instance.

DeserializeAsync
public override ValueTask<T> DeserializeAsync(Stream stream, CancellationToken cancellationToken)
result = jsonSerializer.DeserializeAsync(stream, cancellationToken)

Asynchronously deserializes an object graph from the provided JSON stream.

stream
The stream from which the object graph is deserialized.
cancellationToken
A token that can be used to cancel the deserialization operation.

Retorna: A task representing the asynchronous deserialization operation. The task result contains the deserialized object graph.

SerializeAsync
public override ValueTask SerializeAsync(T graph, Stream stream, CancellationToken cancellationToken)
result = jsonSerializer.SerializeAsync(graph, stream, cancellationToken)

Asynchronously serializes the specified object graph to the provided stream as JSON.

graph
The object graph to serialize.
stream
The stream to which the graph is serialized.
cancellationToken
A token that can be used to cancel the serialization operation.

Retorna: A task representing the asynchronous serialization operation.